﻿@{
    Layout = null;
}
<!DOCTYPE html>

<html>
<head>
    <meta charset="utf-8">
    <meta name="renderer" content="webkit|ie-comp|ie-stand">
    <meta http-equiv="X-UA-Compatible" content="IE=edge,chrome=1">
    <meta name="viewport" content="width=device-width,initial-scale=1,minimum-scale=1.0,maximum-scale=1.0,user-scalable=no" />
    <meta http-equiv="Cache-Control" content="no-siteapp" />

    <script type="text/javascript" src="~/js/jquery-2.2.0.min.js"></script>

    <!--[if lt IE 9]>
    <script type="text/javascript" src="lib/html5shiv.js"></script>
    <script type="text/javascript" src="lib/respond.min.js"></script>
    <![endif]-->
    <link href="static/h-ui/css/H-ui.min.css" rel="stylesheet" type="text/css" />
    <link href="static/h-ui.admin/css/H-ui.login.css" rel="stylesheet" type="text/css" />
    <link href="static/h-ui.admin/css/style.css" rel="stylesheet" type="text/css" />
    <link href="lib/Hui-iconfont/1.0.8/iconfont.css" rel="stylesheet" type="text/css" />
    <!--[if IE 6]>
    <script type="text/javascript" src="lib/DD_belatedPNG_0.0.8a-min.js" ></script>
    <script>DD_belatedPNG.fix('*');</script>
    <![endif]-->
    <title>瑞浦WCS管理系统</title>
     <style>
        .loginBox{
            border:0px;
            box-sizing:border-box;
            background:#fff;
            left:39%;
            top:40%;
            padding:0px;
            display:flex;
            box-shadow: 3px 3px 30px #000000a1;
        }
        .inf{
    text-align: center;
    font-family: '楷体','黑体','雅黑';
    font-size: 3.7rem;
    line-height: 450px;
        }
        #loginform{
          width:1000px;
          height:500px;
          background: #ffffff00;
          border-radius:20px;
        }
        .loginBox .input-text {

                border: solid 2px #000;
    width: 300px;
        }


        .lleft{
            width:50%;
              height:100%;
             background:#000000ac;
             color:#fff;
          border-radius:20px 0 0 20px;
             
        }
        .lright{
             width:50%;
            height:100%;
             background:#fff;
            padding:20px;
            padding-top:120px;
                box-sizing: border-box;
          border-radius:0 20px 20px 0;

        }
        .row{
            margin:0px;
        }

        .loginWraper{
          background: url(images/bg.png);
          background-position: center;
          background-size: cover;
          background-repeat: no-repeat;
          background-size:cover;
          box-sizing: border-box;
          overflow:hidden;
        }

       
    </style>
</head>
<body>
    <input type="hidden" id="TenantId" name="TenantId" value="" />
    @*<div class="header"></div>*@
    <div class="loginWraper">
        <div id="loginform" class="loginBox">
             <div class="lleft"> <h1 class="inf">瑞浦WCS管理系统</h1></div>
            <form class="form form-horizontal lright" method="post" name="form1" id="form1" onsubmit="return Login(); return false;">
                <div class="row cl">
                    <label class="form-label col-xs-3"><i class="Hui-iconfont">&#xe60d;</i></label>
                    <div class="formControls col-xs-8">
                        <input id="userId" name="userId" type="text" placeholder="账户" class="input-text size-L">
                    </div>
                </div>
                <div class="row cl">
                    <label class="form-label col-xs-3"><i class="Hui-iconfont">&#xe60e;</i></label>
                    <div class="formControls col-xs-8">
                        <input id="userPwd" name="userPwd" type="password" placeholder="密码" class="input-text size-L">
                    </div>
                </div>
                <div class="row cl">
                    <div class="formControls col-xs-8 col-xs-offset-3" style="visibility:hidden;">
                        <label for="online">
                            <input type="checkbox" name="online" id="online"  >
                            使我保持登录状态
                        </label>
                    </div>
                    <div class="formControls col-xs-8 col-xs-offset-3" style="visibility:hidden;"> 
                        <label for="online">
                            <input type="checkbox" name="onserlogin" id="onserlogin" value="1" onchange="onCheckChange()">
                            启用刷卡登录
                        </label>
                    </div>
                </div>
                <div class="row cl">
                    <div class="formControls col-xs-8 col-xs-offset-3">
                        <button type="submit" class="btn btn-success radius size-L">&nbsp;登&nbsp;&nbsp;&nbsp;&nbsp;录&nbsp;</button>
                        <button type="reset" class="btn btn-default radius size-L">&nbsp;取&nbsp;&nbsp;&nbsp;&nbsp;消&nbsp;</button>
                    </div>
                </div>
            </form>
        </div>
    </div>
    @*<div class="footer">Copyright 瑞浦兰钧能源股份有限公司</div>*@
    <script type="text/javascript" src="lib/jquery/1.9.1/jquery.min.js"></script>
    <script type="text/javascript" src="static/h-ui/js/H-ui.min.js"></script>
    <script>
        function onCheckChange(){
            var check = $("#onserlogin").val();
            if(check == 1){
                serial();
            }
        }

        function keyLogin() {
            if (event.keyCode == 13)  //回车键的键值为13
                document.getElementById("loginbtn").click(); //调用登录按钮的登录事件
        }
        function Login() {
            var username = $("#userId").val();
            var password = $("#userPwd").val();
            var online = $("#online")[0].checked;
            if (username == "") {
                alert("用户名不能为空");
                return false;
            }
            if (password == "") {
                alert("密码不能为空");
                return false;
            }
            $.ajax({
                type:"POST",
                url: "/home/UserLogin",
                data: $("#form1").serialize(),
                success: function (data) {
                    if (data.result) {
                        window.location = "/Home/Index";
                    }
                    else {
                        alert(data.message);
                    }
                }
            });
            return false;
        }

        //-----------------刷卡登入----------------------\\

         function LoginIc(code) {
           $.ajax({
                type: "POST",
                url: "/home/UserLoginByIc",
               data: {
                   "ic":code
               },
                success: function(data) {
                    if (data.result) {
                        window.location = "/Home/Index";
                    }
                    else {
                        alert(data.message);
                    }
                }
            });
        }
        var a = ""
        $("body").keydown(function(e) {

            if (a.indexOf("Enter") == -1 && !isNaN(e.key)) {
                //console.log(e.key)
                a += e.key
            }

            if (e.key == "Enter") {
                if (a.length == 10) {
                    console.log("输入：" + a.replace(/[^0-9]/g, ''))
                   LoginIc(a.replace(/[^0-9]/g, ''))
                }


                a = ""

            }
        })
        //----------------------------------------------\\
        //TODO 扫卡登录 到时候串口数据类型具体处理
      //  async function serial(){

      //    // 浏览器支持serial
      //    if ('serial' in navigator) {
      //        console.log('当前浏览器支持serial')

      //        const port = await navigator.serial.requestPort()
      //        await port.open({ baudRate: 115200})
      //        console.log("port的内容是：", port);
      //        const reader = port.readable.getReader();

      //        try{
      //            while(true){
      //                const {value,done} = await reader.read();
      //                if (done) {
      //                    reader.releaseLock();
      //                    break;
      //                }
      //                //Commix 串口发送数据处理
      //                let utf8decoder = new TextDecoder('GBK');
      //                let u8arr = new Uint8Array(value);
      //                var code  = utf8decoder.decode(u8arr);
      //                console.log('value的值是：', code);
      //                //串口调试工具发送数据处理
      //                var xCode = Uint8ArrayToString(value);
      //                console.log("测试value的内容是", xCode);
      //                var soures = xCode.split("&");
      //                if(soures.length == 2){
      //                    $("#userId").value = soures[0];
      //                    $("#userPwd").value = soures[1];
      //                    Login(); //调用登录按钮的登录事件
      //                }
      //            }
      //        }catch (error) {
      //            console.error(error)
      //        }finally {
      //            reader.releaseLock();
      //            console.log('允许稍后关闭串口。');
      //            await readableStreamClosed.catch(() => { /* Ignore the error */ });
      //            await port.close();
      //        }
      //    }
      //}

      //function Uint8ArrayToString(serialData){
      //    var out, i, len, c;
      //    var char2, char3;

      //    out = "";
      //    len = serialData.length;
      //    i = 0;
      //    while(i < len) {
      //        c = serialData[i++];
      //        switch(c >> 4)
      //        {
      //            case 0: case 1: case 2: case 3: case 4: case 5: case 6: case 7:
      //            // 0xxxxxxx
      //            out += String.fromCharCode(c);
      //            break;
      //            case 12: case 13:
      //            // 110x xxxx   10xx xxxx
      //            char2 = serialData[i++];
      //            out += String.fromCharCode(((c & 0x1F) << 6) | (char2 & 0x3F));
      //            break;
      //            case 14:
      //                // 1110 xxxx  10xx xxxx  10xx xxxx
      //                char2 = serialData[i++];
      //                char3 = serialData[i++];
      //                out += String.fromCharCode(((c & 0x0F) << 12) |
      //                    ((char2 & 0x3F) << 6) |
      //                    ((char3 & 0x3F) << 0));
      //                break;
      //        }
      //    }
      //    return out;
      //}



    </script>
</body>
</html>
